import request from '@/utils/request'

export interface ImportRecord {
  id: number
  fileName: string
  fileSize: number
  totalCount: number
  successCount: number
  failCount: number
  status: 'SUCCESS' | 'FAILED' | 'PARTIAL' | 'PROCESSING'
  errorMessage?: string
  errorFile?: string
  type: string
  createdAt: string
  updatedAt: string
}

export interface ImportQuery {
  page: number
  size: number
  type?: string
  status?: string
}

export const importApi = {
  // 获取导入历史
  getImportHistory(params: ImportQuery) {
    return request.get('/import/history', { params })
  },

  // 获取导入记录详情
  getImportRecord(id: number) {
    return request.get(`/import/records/${id}`)
  },

  // 下载错误报告
  downloadErrorFile(id: number) {
    return request.get(`/import/records/${id}/error-file`, {
      responseType: 'blob'
    })
  },

  /**
   * 下载导入模板
   */
  downloadTemplate: () =>
    request.get('/import/template', { 
      responseType: 'blob'
    })
}